//
//  UIBarButtonItem+HMSettringItem.m
//  OC版本新浪微博
//
//  Created by 赵少朋赵少朋 on 17/1/18.
//  Copyright © 2017年 ITheima. All rights reserved.
//

#import "UIBarButtonItem+HMSettringItem.h"

@implementation UIBarButtonItem (HMSettringItem)

- (instancetype)initWithImgName:(NSString *)imgName title:(NSString *)title target:(id)target action:(SEL)action {

    UIButton *barBtn = [[UIButton alloc] init];
    
    if (imgName.length > 0) {
        
        [barBtn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
        [barBtn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imgName]] forState:UIControlStateHighlighted];
        [barBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    if (title.length > 0) {
        [barBtn setTitle:title forState:UIControlStateNormal];
        [barBtn setTitleColor:ThemeColor forState:UIControlStateHighlighted];
        [barBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
    }
    [barBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    [barBtn sizeToFit];
    return [[UIBarButtonItem alloc] initWithCustomView:barBtn];
    
}


@end
